import React from 'react'
import { increment, decrement } from '../../store/Slice/countSlice'
import { useDispatch } from 'react-redux'
import { useSelector } from 'react-redux'

export default function Count() {
  const dispatch = useDispatch()
  const count = useSelector(state=>state.count.count)
  const movieList = useSelector(state=>state.movie.movieList)

  const incrementHandle = () => {
    dispatch(increment(9))

  }

  const decreamentHandle = () => {
    dispatch(decrement(2))
  }

  const ifOddIncrementHandle = () => {
    if(count%2!==0){
      dispatch(increment(4))
    }
  }

  const waitDecrementHandle = () => {

  }

  return (
    <div>
      <h1>我是Count组件 我的值是{count}</h1>
      <h1>电影列表的个数是{movieList.length}</h1>
      <div>
        <button onClick={incrementHandle}>累加</button>
        <button onClick={decreamentHandle}>累减</button>
        <button onClick={ifOddIncrementHandle}>如果是奇数再加1</button>
        <button onClick={waitDecrementHandle}>等2s再加1</button>
      </div>

    </div>
  )
}
